//
//  ViewController.swift
//  BWThemeKit
//
//  Created by 朱旭宏 on 03/23/2022.
//  Copyright (c) 2022 朱旭宏. All rights reserved.
//

import UIKit

class ViewController: UIViewController{
    @IBOutlet weak var themeSC: UISegmentedControl!{
        didSet{
            themeSC.selectedSegmentIndex = DemoTheme.shared.currentStyle.rawValue
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        updateThemeStyleIfNeeded()
    }
    
    @IBAction func changeTheme(_ sender: UISegmentedControl) {
        guard let style = DemoThemeStyle(rawValue: sender.selectedSegmentIndex) else {
            return
        }
        DemoTheme.shared.updateStyle(with: style)
    }
}

class View: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupThemeIfNeeded()
    }
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    override func awakeFromNib() {
        super.awakeFromNib()
    }
    
    func setupThemeIfNeeded(){
        
    }
}

extension ViewController: DemoThemeAdaptableResponder {
    func updateThemeIfNeeded(style: DemoThemeStyle) {
        view.backgroundColor = .use(DemoThemeColor.Common.red)
    }
}
